import java.util.Map;
import java.util.PriorityQueue;
import java.util.TreeMap;

public class Demo {
    public static void main(String[] args) {
        PriorityQueue<int[]> queue = new PriorityQueue<>((a,b)->b[0]-a[0]);

    }
}
class Solution {
    public long maxKelements(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((a,b)->b-a);
        for(int i=0; i<nums.length; i++){
            queue.offer(nums[i]);
        }
        Long ans = 0L;
        while(!queue.isEmpty() && k > 0){
            int tmp = queue.poll();
            ans += tmp;
            tmp = (tmp+2)/3;
            queue.offer(tmp);
            k--;
        }
        return ans;
    }
}